#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow) {
    ui->setupUi(this);

    m_Server = new ServerTcp();
    if (!m_Server->startServer(12345)) {
        qDebug() << "服务器启动失败!";
        QMessageBox::critical(this, "错误", "无法启动服务器!");
        return;
    }
    m_HandleLogin = new HandleLoginRequest("SQLite/IOTMonitoring.db");

    connect(m_Server, &ServerTcp::onServerLogin,m_HandleLogin, &HandleLoginRequest::LoginVerification);
    connect(m_HandleLogin, &HandleLoginRequest::isLoginVerification,
        m_Server, &ServerTcp::onRespondClientLogin);

    qDebug() << "服务器对象线程:" << m_Server->thread();
    qDebug() << "处理对象线程:" << m_HandleLogin->thread();
}

MainWindow::~MainWindow() {
    delete ui;
}

